package logic

import (
	"context"
	"doctor-medicine-system/models"

	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailLogic {
	return &DetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 查询
func (l *DetailLogic) Detail(in *doctorrpc.DetailRequest) (*doctorrpc.DetailResponse, error) {
	// todo: add your logic here and delete this line

	var medicine models.Medicine
	if err := medicine.DetailMedicine(models.DB, in.MedicineId); err != nil {
		return nil, err
	}

	return &doctorrpc.DetailResponse{
		Name:  medicine.Name,
		Image: medicine.Image,
		Price: float32(medicine.Price),
		Num:   int64(medicine.Num),
	}, nil
}
